package net.sea.setup.ui.wizard.factory.db.impl;

import net.sea.commons.constants.AppConstants;
import net.sea.commons.util.StringUtils;
import net.sea.setup.ui.wizard.enums.OpEvent;
import net.sea.setup.ui.wizard.factory.db.DataBase;
import net.sea.setup.ui.wizard.factory.db.IDBType;

/**
 * 
 * @author 华成伍
 *
 */
public class SQLServer implements IDBType {
	/**
	 * 默认端口
	 */
	private final static int DEFAULT_PORT = 1433;

	@Override
	public void fillDBInfo(DataBase db) {
		if (db == null) {
			return;
		}
		db.setDbNameTip("数据库名称：");
		if (db.getOpType() != OpEvent.ModifyEvent) {
			db.setPort(DEFAULT_PORT);
		}
		StringBuffer url = new StringBuffer();
		url.append("jdbc:microsoft:sqlserver://")
				.append(StringUtils.isEmpty(db.getHost()) ? "<host>" : db
						.getHost())
				.append(":")
				.append(db.getPort() == null ? DEFAULT_PORT : db.getPort())
				.append(";DatabaseName=")
				.append(StringUtils.isEmpty(db.getDbName()) ? "<dbname>" : db
						.getDbName());
		db.setUrl(url.toString());
//		db.setDriverClass("com.microsoft.sqlserver.jdbc.SQLServerDriver");
		db.setDriverClass("com.microsoft.jdbc.sqlserver.SQLServerDriver");
		db.setDefaultDriverJar(AppConstants.SYSTEM_PATH
				+ "/install/lib/jdbc/mssqlserver.jar");

	}

}
